package com.trydm.controller;

import com.trydm.model.Ad;
import com.trydm.service.AdService;
import com.trydm.util.R;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhujinrun
 * @since 2024-03-22
 */
@RestController
@RequestMapping("/ad")
public class AdController {

    private final AdService adService;

    public AdController(AdService adService) {
        this.adService = adService;
    }

    @GetMapping("/list")
    public R getList() {
        return R.ok().put("data", adService.list());
    }

    @GetMapping("count")
    public R count() {
        return R.ok().put("data", adService.count());
    }

    @GetMapping("info/{id}")
    public R info(@PathVariable("id") Long id) {
        return R.ok().put("data", adService.getById(id));
    }

    @GetMapping("delete/{id}")
    public R delete(@PathVariable("id") Long id) {
        return R.ok().put("data", adService.removeById(id));
    }

    @PostMapping("save")
    public R save(@RequestBody Ad ad) {
        return R.ok().put("data", adService.save(ad));
    }

    @PostMapping("saveBatch")
    public R saveBatch(@RequestBody List<Ad> ads) {
        return R.ok().put("data", adService.saveBatch(ads));
    }

}
